# Maintainer: Fabian Bornschein <fabiscafe-at-mailbox-dot-org>
# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

pkgbase=libpeas
pkgname=(
  libpeas
  libpeas-demos
  libpeas-docs
)
pkgver=1.36.0
pkgrel=4
pkgdesc="GObject Plugin System"
url="https://wiki.gnome.org/Projects/Libpeas"
arch=(loong64 x86_64)
license=(LGPL)
depends=(
  gobject-introspection-runtime
  gtk3
)
makedepends=(
  gi-docgen
  git
  glade
  gobject-introspection
  lua51-lgi
  luajit
  meson
  python-gobject
  vala
)
checkdepends=(xorg-server-xvfb)
_commit=7f245fa5158204621c3469756a951b68a651c4fe  # tags/libpeas-1.36.0^0
source=("git+https://gitlab.gnome.org/GNOME/libpeas.git#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd libpeas
  git describe --tags | sed 's/^libpeas-//;s/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd libpeas
}

build() {
  local meson_options=(
    -D gtk_doc=true
    -D vapi=true
  )

  arch-meson libpeas build "${meson_options[@]}"
  meson compile -C build
}

check() {
  xvfb-run -s '-nolisten local' \
    meson test -C build --print-errorlogs
}

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

package_libpeas() {
  optdepends=(
    'lua51-lgi: Lua loader'
    'python-gobject: Python loader'
  )
  provides=(libpeas{,-gtk}-1.0.so)

  meson install -C build --destdir "$pkgdir"

  cd "$pkgdir"

  _pick demo usr/bin/peas-demo
  _pick demo usr/lib/peas-demo

  _pick docs usr/share/doc
}

package_libpeas-demos() {
  pkgdesc+=" (demo applications)"
  depends=(
    libpeas
    python-gobject
  )
  mv demo/* "$pkgdir"
}

package_libpeas-docs() {
  pkgdesc+=" (documentation)"
  depends=()
  mv docs/* "$pkgdir"
}

# vim:set sw=2 sts=-1 et:
